class Solution(object):
    def summaryRanges(self, nums):
        """
        :type nums: List[int]
        :rtype: List[str]
        """
        if not nums:
            return []
        n = len(nums)
        left_index = 0
        right_index = 1
        out = []
        while right_index < n:
            if nums[right_index] - nums[right_index - 1] > 1:
                if right_index - left_index == 1:
                    out.append(str(nums[left_index]))
                else:
                    out.append(str(nums[left_index]) + '->' + str(nums[right_index - 1]))
                left_index = right_index
            right_index += 1
        if right_index - left_index == 1:
            out.append(str(nums[left_index]))
        else:
            out.append(str(nums[left_index]) + '->' + str(nums[right_index - 1]))
        return out


data = Solution()
nums = [0, 1, 2, 4, 5, 7]
print(data.summaryRanges(nums))
